package com.leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No77
 * @description
 * @date 2021/3/3 下午12:14
 */
public class No77 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<List<Integer>> res = combine(n,k);
        for (int i = 0; i < res.size(); i++) {
            List<Integer> temp = res.get(i);
            for (int j = 0; j < temp.size(); j++) {
                System.out.print(temp.get(j));
                System.out.print(" ");
            }
            System.out.println();
        }

    }

    public static List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> res = new ArrayList<>();
        if(n < 1 || k < 1 || k > n){
            return res;
        }
        List<Integer> list = new ArrayList<>();
        subCombine(n,k,res,list,0);
        return res;
    }

    private static void subCombine(int n, int k, List<List<Integer>> res, List<Integer> list, int i) {
        if(k == 0){
            res.add(new ArrayList<>(list));
            return;
        }
        for (int j = i + 1; j <=n ; j++) {
            list.add(j);
            subCombine(n,k - 1,res,list,j);
            list.remove(list.size() - 1);
        }
    }

}
